<?php
/** 
 * @uses 		服务器数据发送
 * @author 		Duan
 * @version 	1.0
 * @copyright	Yihuan							  
 */

namespace Common\Model;


class PushModel 
{

	/**
	 * @uses HIS数据发送
	 */
	public static function pushData()
	{
		$redis 	= \Common\Model\ServeModel::serveRedis();
		$pushKey= C('PUSH_KEY');
		$send 	= $redis->lpop($pushKey);
		if (!$send) { echo 'noData to be Push , 时间：'.time();die;} 
		$url 	= C('URL_CLOUD');
		$data   = json_decode($send , true);
		$result = curlPost($url , $data);
		$fileContent    = [
            'hospitalId'=> C('KEY'),
            'type'      => C('LOG_PATH_TYPE'),
            'send'    	=> $send,
            'result'    => $result,
        ];
		if (C('LOG_PATH_TYPE') == 1) {
            \Common\Model\LogModel::setLog(json_encode($fileContent , JSON_UNESCAPED_UNICODE));
        } else {
			writeLog(APP_LOG_PATH.'Log/'.$pushKey.'/' , date('Ymd_His') , var_export($fileContent , true));
        }
		$result['code'] != 200 && $redis->rpush($pushKey , $send);
	}

	/**
	 * @uses 日志数据发送
	 */
	public static function pushLog()
	{
		$redis 	= \Common\Model\ServeModel::serveRedis();
		$logKey = C('LOG_KEY');
		$send 	= $redis->lpop($logKey);
		if (!$send) die;	
		$url 	= C('URL_LOG');
		$data   = json_decode($send , true);
		$result = curlPost($url , $data);
		$result['code'] != 200 && $redis->rpush($logKey , $send);
	}
}